import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LeetCode2215 {
    public static void main(String[] args) {
        findDifference(new int[]{3,3},new int[]{3});

    }

    public static List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
        List<List<Integer>> result = new ArrayList<>(2);

        int containerLength = 0;
        List<Integer> numsIndex1 = new ArrayList<>();
        List<Integer> numsInsex2 = new ArrayList<>();
        for (int i = 0; i < nums1.length; i++){
            for (int k = 0; k < nums2.length; k++){
                if(nums1[i] == nums2[k]){
                    numsIndex1.add(i);
                    numsInsex2.add(k);
                    containerLength++;
                }
            }
        }

        ArrayList<Integer> list1 = new ArrayList<Integer>(nums1.length - containerLength + 1);
        for (int i = 0; i < nums1.length; i++){
            if (!numsIndex1.contains(i)){
                list1.add(nums1[i]);
            }
        }

        ArrayList<Integer> list2 = new ArrayList<>(nums2.length - containerLength + 1);
        for (int i = 0; i < nums2.length; i++){
            if (!numsInsex2.contains(i)){
                list2.add(nums2[i]);
            }
        }

        result.add(removeDuplicates(list1));
        result.add(removeDuplicates(list2));
        return  result;
    }

    public static List<Integer> removeDuplicates(ArrayList<Integer> list) {
        HashSet<Integer> set = new HashSet<>(list);
        return new ArrayList<>(set);
    }

    public List<List<Integer>> findDifference1(int[] nums1, int[] nums2) {
        List<List<Integer>> ret = new ArrayList<>(2);
        Set<Integer> nums1Set = new HashSet<>(nums1.length);
        for (int i : nums1) {
            nums1Set.add(i);
        }

        Set<Integer> set1 = new HashSet<>(nums1.length);
        Set<Integer> set2 = new HashSet<>(nums2.length);
        for (int i : nums2) {
            if (!nums1Set.contains(i)) {
                set2.add(i);
            }else{
                set1.add(i);
            }
        }

        nums1Set.removeAll(set1);
        //nums1Set.removeAll(set2);
        ret.add(new ArrayList<>(nums1Set));
        ret.add(new ArrayList<>(set2));
        return ret;
    }
}
